/**
 * Created by zhang on 2016/9/23.
 */
    $(document).ready(function(){
        get_keywords_data();
        get_site_data();
        get_proxy_data();
        //get_map();
    });

function get_keywords_data(){
    $.getJSON("/keywords",function(result){
        //console.log(result['data'].count);
        if(result!=null){
            if(result.err=='ok'){
                $('#keywords').html(result['data'].count);
            }
        }
    });
}

function render_proxy(){
    /**
     * Created by zhang on 2016/9/21.
     */

}

function get_site_data(){
    $.getJSON("/site",function(result){
        //console.log(result['data'].count);
        if(result!=null){
            if(result.err=='ok'){
                $('#site').html(result['data'].count);
            }
        }
    });
}
var t1=180000;
function get_proxy_data(){
    $.getJSON("/proxies",function(result){
        //console.log(result['data'].count);
        if(result!=null){
            if(result.err=='ok'){


                var dom = document.getElementById("revenue-chart");
                var myChart = echarts.init(dom);
                var app = {};
                option = null;
                var proxies=result['data']['proxies'].proxies;
                //var proxies_array=[];
                //function randomData(){
                //    for(var item in proxies){
                //        var v2=proxies[item];
                //        //console.log(v2);
                //        var data_item={name: item.toString(),value:[item,v2]};
                //    }
                //    return data_item;
                //}
                var data = [];
                var now = +new Date(1997, 9, 3);
                var oneDay = 24 * 3600 * 1000;
                //var value = Math.random() * 1000;
                //for (var i = 0; i < 1000; i++) {
                //    data.push(randomData());
                //}
                for(var item in proxies){
                    var v2=proxies[item];
                    //console.log(v2);
                    var data_item={name: item.toString(),value:[item,v2]};
                    data.push(data_item);
                    //proxies_array.push(data_item);
                }

                //console.log(proxies_array);
                option = {
                    tooltip: {
                        trigger: 'axis',
                        formatter: function (params) {
                            params = params[0];
                            var date = new Date(params.name);
                            return date.getDate() + '/' + (date.getMonth() + 1) + '/' + date.getFullYear() + '/'+date.getHours()+':'+date.getMinutes()+':'+date.getSeconds()+' : ' + params.value[1];
                        },
                        axisPointer: {
                            animation: false
                        }
                    },
                    xAxis: {
                        type: 'time',
                        splitLine: {
                            show: false
                        }
                    },
                    yAxis: {
                        type: 'value',
                        boundaryGap: [0, '100%'],
                        splitLine: {
                            show: false
                        }
                    },
                    series: [{
                        name: '模拟数据',
                        type: 'line',
                        showSymbol: false,
                        hoverAnimation: false,
                        data: data
                    }]
                };
                //console.log(result['data']['proxies'].proxies);

                app.timeTicket = setInterval(function () {
                       for(var j=0;j<15;j++){
                           data.shift();
                           data.push(proxies);
                           //console.log(proxies_array.shift());
                       }

                    myChart.setOption({
                        series: [{
                            data: data
                        }]
                    });
                }, 1000);;
                if (option && typeof option === "object") {
                    myChart.setOption(option, true);
                }



            }
        }
    });
    setTimeout("get_proxy_data()",180000);
}

